<div class="search-res-mask"></div>
<div class="search-res">
    <div class="search-res-btn hide-pc">
        <button class="layui-btn" id="search-btn"><i class="layui-icon">&#xe615;</i>查询</button>
    </div>
    <div class="content-search search-fix">
        <div class="layui-form layui-form-pane">
            <div class="layui-inline">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" value="${name!}" placeholder="请输入名称" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn" id="btn_search" lay-submit="">查询</button>
                <button class="layui-btn layui-btn-primary hide-pc" id="search-close">关闭</button>
            </div>
        </div>
    </div>
</div>
<div class="tar mt10">
    <#if shiro.hasPermission("sys:admin:insert")>
        <a class="layui-btn layui-btn-normal layui-btn-small" href="admin/edit">+添加</a>
    </#if>
</div>
<div class="table-list">
    <table class="layui-table layui-list-table">
        <thead>
        <tr>
            <th>用户名</th>
            <th>状态</th>
            <th>手机</th>
            <th>邮箱</th>
            <th>注册时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <#list data as d>
            <tr>
                <td class="layui-table-first"><i class="layui-table-hd">名称</i><span
                        class="layui-table-bd">${d.name}</span></td>
                <td><i class="layui-table-hd">状态</i><span class="layui-table-bd">${d.statusText}</span></td>
                <td><i class="layui-table-hd">手机</i><span class="layui-table-bd">${d.phone!}</span></td>
                <td><i class="layui-table-hd">邮箱</i><span class="layui-table-bd">${d.mail!}</span></td>
                <td><i class="layui-table-hd">注册时间</i><span class="layui-table-bd">${d.registetime?string("yyyy-MM-dd HH:mm:ss")}</span>
                </td>
                <td>
                    <#if shiro.hasPermission("sys:admin:update")>
                        <button class="layui-btn layui-btn-warm layui-btn-small"
                                onclick="location.href='/administrate/admin/edit?id=${d.id}'">修改
                        </button>
                    </#if>
                    <#if shiro.hasPermission("sys:admin:resetpwd")>
                        <button class="layui-btn layui-btn-danger layui-btn-small btn_resetpwd" data-id="${d.id}">重置密码
                        </button>
                    </#if>
                    <#if shiro.hasPermission("sys:logging:list")>
                        <button class="layui-btn layui-btn-small"
                                onclick="location.href='/administrate/loginlog?adminID=${d.id}'">登录日志
                        </button>
                    </#if>
                    <#if shiro.hasPermission("sys:commitlog:list")>
                        <button class="layui-btn layui-btn-small"
                                onclick="location.href='/administrate/commitlog?adminID=${d.id}'">操作日志
                        </button>
                    </#if>
                </td>
            </tr>
        </#list>
        </tbody>
    </table>
</div>
<!-- 分页 -->
<div id="pages" class="tac"></div>
<#macro script>
    <script>
        layui.use(['jquery', 'laypage', 'form'], function () {
            var $ = layui.jquery, laypage = layui.laypage, form = layui.form;
            $(function () {
                /*弹出搜索*/
                $(document).on('click', '#search-btn', function () {
                    $('.search-res-mask').show();
                    $(this).parent().siblings('.search-fix').addClass('cur');
                });
                /*搜索*/
                $("#btn_search").on('click', function () {
                    reload(1);
                });
                /*关闭搜索*/
                $(document).on('click', '#search-close', function () {
                    $('.search-res-mask').hide();
                    $(this).parents('.search-fix').removeClass('cur');
                });
                /*重置密码*/
                $(".btn_resetpwd").on("click", function () {
                    var id = $(this).data("id");
                    layer.confirm('重置该管理员密码为123456,是否继续?', {icon: 7, title: '警告', btn: ['是', '否']}, function () {
                        $.ajax({
                            type: "POST",
                            url: "/administrate/admin/resetpwd",
                            data: {id: id},
                            async: false,
                            dataType: "json",
                            success: function (result) {
                                layer.msg(result.msg);
                            }
                        });
                    });
                });
            });
            laypage.render({
                elem: 'pages'
                , layout: ['prev', 'page', 'next', 'count']
                , count: ${dataCount}
                , limit: ${pageSize}
                , curr: ${pageNo}
                , groups: 2
                , jump: function (obj, first) {
                    if (!first) {
                        reload(obj.curr)
                    }
                }
            });

            function reload(currPage) {
                var name = $("input[name='name']").val();
                location.href = window.location.pathname + "?name=" + name + "&pageNo=" + currPage;
            }
        });
    </script>
</#macro>